<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>业主列表</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<table id="roleList" class="roleList" lay-filter="roleList"></table>
<input type="hidden" th:value="${plotId}" id="plotId">
<script type="text/html" id="barEdit">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="sratus">
    <input type="checkbox" name="id" value="{{d.id}}" title="审核通过" lay-filter="lockStatus" {{ d.status == 1 ?'checked' : '' }}>
</script>
<script th:src="@{/src/layui.js}"></script>
<script>
    layui.use(['jquery','layer','laypage','laytpl','table','form'],function () {
        var $ = layui.jquery,
            layer = layui.layer,
            laypage = layui.laypage,
            laytpl = layui.laytpl,
            table = layui.table,
            form = layui.form;
        table.render({
            elem:'#roleList',
            url:'/plot/userList',
            title:'业主列表',
            page:true,
            limit:10,
            cols:[
                [
                    {type:'checkbox'},
                    {title:'ID',field:'id',width:50},
                    {title:'业主账户',field:'account'},
                    {title:'手机号码',field:'phoneNumber'},
                    {title:'业主姓名',field:'userName'},
                    {title:'业主性别',field:'sex'},
                    {title:'身份证号码',field:'idCard'},
                    {title:'角色',field:'role'},
                    {title:'邮箱',field:'email'},
                    {title:'审核状态',field:'status',templet:'#sratus'},
                    {title:'创建时间',field:'createTime'},
                    {title:'操作',templet:'#barEdit'}
                ]
            ],
            where:{plotId:$('#plotId').val()},
            parseData:function(result){
                return {
                    code:result.code==200?0:result.code,
                    msg:result.message,
                    count:result.data.total,
                    data:result.data.list
                }
            }
        });

        //监听锁定事件
        form.on('checkbox(lockStatus)',function (data) {
            var id = data.elem.value;
            var status = data.elem.checked?1:0;
            $.ajax({
                url:'/plot/checkUser',
                data:{id:id,status:status},
                type:'put',
                dataType:'json',
                success:function (res) {
                    if(res.code == 200){
                        layer.msg('更新成功',{icon:1,time:1000},function () {
                            table.reload('dynamicList',{});
                        })
                    }else{
                        layui.msg('更新失败',{icon:5})
                    }
                }
            })
        })

        //监听表格的行工具事件
        table.on('tool(roleList)',function (row) {
            var data = row.data;
            if(row.event === 'del'){
                layer.confirm("确定删除吗？",function (index) {
                    $.ajax({
                        url:'/user/delete',
                        type:'delete',
                        data:{'id':data.id},
                        dataType:'json',
                        success:function (result) {
                            if (result.code == 200){
                                layer.msg(result.message,{icon:1},function () {
                                    location.reload();//删除成功刷新页面
                                });
                            } else {
                                layer.msg(result.message,{icon:5});
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        })




    })
</script>

</body>
</html>